blob: 4666add5875dfe1b329108090920ea86dd517600 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
import axios from 'axios';
import { useRouter } from 'next/router';
import { useEffect, useState } from 'react';
import Seo from '@/core/components/Seo';
import dynamic from 'next/dynamic';
const BasicLayout = dynamic(() =>
import('@/core/components/layouts/BasicLayout')
);
const ProductSearch = dynamic(() =>
import('@/lib/product/components/ProductSearch')
);
const BASE_URL = 'https://indoteknik.com';
export default function FindPage() {
const route = useRouter();
const url = BASE_URL + route.asPath;
const [result, setResult] = useState(null);
const [query, setQuery] = useState(null);
const getUrls = async (url) => {
try {
let response = await axios(
`${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/url-category_brand?url=${url}`
);
let result = response?.data?.response?.docs[0] || null;
setResult(result);
} catch (error) {
console.error('Error fetching data:', error);
}
};
useEffect(() => {
getUrls(url);
}, []);
useEffect(() => {
if (result) {
let fq = `category_parent_ids:${result.category_id_i} AND manufacture_id_i:${result.brand_id_i}`;
setQuery({
fq : fq
});
}
}, [result]);
return (
<BasicLayout>
{query && <ProductSearch query={query} prefixUrl={`${route.asPath}`} />}
</BasicLayout>
);
}
|